<template>
    <div id="dv">
        <div>
          <el-form ref="registerForm">
            <el-form-item  prop="phone">
              <el-input v-model="mobile" placeholder="手机号码">
              </el-input>
            </el-form-item>
            
            <el-form-item prop="psw">
              <el-input v-model="inputPassword" placeholder="密码" :maxlength="20">
              </el-input>
            </el-form-item>
            <el-form-item>
              <el-button   @click.prevent="submitForm('registerForm')">登陆</el-button>
            </el-form-item>
           
          </el-form>
        </div>
    </div>
</template>


<script>
import { $service } from "@/service/reqService";
import { time } from "@/shared/utils/date.js";
import { myUuid } from "@/shared/utils/uuid.js";

export default {
  name: "Login",
  data() {
    return {
      mobile: "",
      inputPassword: "",
      sourceResult_login:'',
      saltResult_login:'',
      password:''
    };
  },
  methods: {
    submitForm() {
      let _this = this;

      // 1.r_i进行Md5
      let r_iMd5Params_login = {
        source: "RE" + time + myUuid,
        salt: "",
        encode32: false
      };
      var getData1 = $service.funcMd5("secret/md5", r_iMd5Params_login).then(response => {
        this.sourceResult_login = response.data.data;
      });


      // 2.手机号进行MD5
      let pswMd5Params_login = {
        source: this.inputPassword,
        salt: this.mobile,
        encode32: true
      };



      getData1.then(function(){
        return $service.funcMd5("secret/md5", pswMd5Params_login).then(response => {
          _this.saltResult_login = response.data.data
        });
      }).then(function(){
        // 3.aes
        let aesParams = {
          source: _this.saltResult_login,
          salt: _this.sourceResult_login,
          encode32: true
        };
        return $service.funcAes("secret/aes", aesParams).then(response => {
          _this.password = response.data.data
        });
      }).then(function(){
        // 4.用户登录
        let data = {
          mobile: _this.mobile,
          password: _this.password
        };
        return $service.insert("customer/login", data).then(response => {
            console.log(response.data); 
            _this.$store.commit('user_info',response.data.data) 
            _this.$router.push({path:'/usercenter'})
        });
      })   
    }
  }
};
</script>

<style scoped>
</style>
